package one.two.six;

public class Rotation {

	private static boolean rot(String a, String b) {
		if (a.length() == b.length()) {
			String m = "";
			String s = "";
			for (int i = 0; i < a.length(); i++) {
				for (int j = i + 1; j <= a.length(); j++) {
					s = a.substring(i, j);
					if (b.indexOf(s) >= 0 && s.length() > m.length()) {
						m = s;
					}
				}
			}

			String r = "";
			if (a.indexOf(m) == 0) {
				r = a.substring(m.length());
			} else {
				r = a.substring(0, a.indexOf(m));
			}

			if (b.indexOf(r) >= 0 && m.length() + r.length() == a.length()) {
				return true;
			}
		}
		return false;
	}

	public static void main(String[] args) {
		String a = "ACTGACG";
		String b = "TGACGAC";
		System.out.println(rot(a, b));
	}

}
